/*
 * xengine_mysql.h
 *
 *  Created on: 2009-8-10
 *      Author: wyb
 */

#ifndef XENGINE_MYSQL_H_
#define XENGINE_MYSQL_H_

#include "util.h"
#include "log.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <mysql/mysql.h>

#define URL "10.2.225.199"
#define DB "xengine_forecast"
#define USERNAME "root"
#define PASSWORD "admin"

#define DEFAULT_FIELD "cpu"

struct computer {
	int id;
	char computer_name[256];
	char ip[256];
};

struct app {
	int id;
	char app_name[256];
	double period;
};

struct app_array {
	int N;
	struct app *data;
};

void xengine_mysql_init(char *url, char *db, char *username, char *password);

void xengine_mysql_close();

struct computer *get_computer(char *computer_name);

struct app *get_app(char *app_name);

struct app_array *get_apps();

struct double_array *get_history(int app_id, char *filed);

struct double_array *get_part_history(int app_id, char *filed, int num,
		time_t *new_time);

int update_app_period(int app_id, double period);

int insert_forecast(int app_id, char *field, double value, time_t time);

int insert_app_history(int app_id, char *field, double value, time_t time);

int insert_app(char *app_name);

int insert_computer(char *computer_name);

int insert_computer_app(int app_id, int computer_id, char *field, double value,
		time_t time);

int insert_computer_history(int computer_id, char *field, double value,
		time_t time);

#endif /* XENGINE_MYSQL_H_ */
